<?php
require_once('pworks/mvc/IFilter.iface.php');
require_once('pworks/mvc/IAction.iface.php');
require_once('pworks/common/cache/impl/ApcCache.class.php');
require_once('pworks/common/httputil/DefaultHttpInputValidation.class.php');
require_once('pworks/common/httputil/HttpConst.class.php');
require_once('pworks/common/exception/SystemException.class.php');
require_once('pworks/util/SessionHelper.class.php');

class WSClientTokenFilter implements IFilter {
	public function before(IAction &$action) {
        //var_dump($_COOKIE);
        if (!trim($_COOKIE["__sessid__"])) {
            list($usec, $sec) = explode(" ", microtime());
            $sessid = "sessid".md5(time().((float)$usec+(float)$sec));
            setcookie("__sessid__", $sessid);
            $_COOKIE["__sessid__"] = $sessid;
        }
        $_REQUEST["__token__"] = WS_TOKEN;
        
        if(isset($_SERVER['PHP_AUTH_USER'])){
			SessionHelper::set('auth_user', $_SERVER['PHP_AUTH_USER']);
        }
        
        return null;
	}

	public function after(IAction &$action) {

		if (TRUE == $action->ut)
		{
			return 'succ';
		}
		return null;
	}
}
